//
//  ManagementData.m
//  QRMaster
//
//  Created by myApple on 16/5/5.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "ManagementData.h"
#import "ManagementModel.h"
#import "RequestNetWork.h"

@interface ManagementData()
{
    NSMutableArray * managementArray;
    NSMutableArray * firstSectionArray;
    NSMutableArray * secondeSectionArray;
    NSMutableArray * thirdSectionArray;
}

@end

@implementation ManagementData

-(id)init
{
    self = [super init];
    if (self) {
        managementArray = [[NSMutableArray alloc]init];
        firstSectionArray = [[NSMutableArray alloc]init];
        secondeSectionArray = [[NSMutableArray alloc]init];
        thirdSectionArray = [[NSMutableArray alloc]init];
    }
    return self;
}

-(void)getMyPowerBlock:(void (^)(NSMutableArray *, NSString *))resultBlock
{
    NSUserDefaults * userInfo = [NSUserDefaults standardUserDefaults];
    RequestNetWork * rnk = [[RequestNetWork alloc]init];
    NSMutableDictionary * postDict = [[NSMutableDictionary alloc]init];
    [postDict setValue:[userInfo objectForKey:@"uid"] forKey:@"id"];
    [postDict setValue:[userInfo objectForKey:@"token"] forKey:@"token"];
    [postDict setValue:[QRSingleton sharedQRSingleton].communityId forKey:@"communityId"];
    [rnk initWithPath:POST(MYSELFPOWER) params:postDict block:^(id downLoadData, id error) {
        if (downLoadData) {
            NSArray * power = [downLoadData objectForKey:@"data"];
        }
        else
        {
            resultBlock(nil,[error objectForKey:@"info"]);
        }
    }];
}

//-(NSMutableArray *)getPower:(NSArray *)power
//{
//    for (NSString * powerIndex in power) {
//        switch ([powerIndex integerValue]) {
//            case constant:
//                statements
//                break;
//                
//            default:
//                break;
//        }
//    }
//}

-(NSMutableArray *)getManageArrayWithRole:(NSInteger)roleIndex
{
    switch (roleIndex) {
        case 1:
            [self administratorArray];
            break;
        case 2:
            [self subAdministratorArray];
            break;
        case 3:
            [self staffArray];
            break;
        case 5:
            [self guestManagementArray];
            break;
        default:
            [self staffArray];
            break;
            
    }
    return managementArray;
}

#pragma mark -------- 获取超级管理数据
-(void)administratorArray
{
    [self clearAllArray];
    [self initStaffData];
    [self initGuestData];
    [self initCommunitysData];
    [self initCommuntiyManageData];
    [managementArray addObject:firstSectionArray];
    [managementArray addObject:secondeSectionArray];
    [managementArray addObject:thirdSectionArray];
}

#pragma mark -------- 获取子管理数据
-(void)subAdministratorArray
{
    [self clearAllArray];
    [self initStaffData];
    [self initGuestData];
    [self initCommunitysData];
    [managementArray addObject:firstSectionArray];
    [managementArray addObject:thirdSectionArray];
}

#pragma mark -------- 获取职员数据
-(void)staffArray
{
    [self clearAllArray];
    [self initStaffData];
    [self initCommunitysData];
    [managementArray addObject:firstSectionArray];
    [managementArray addObject:thirdSectionArray];
}

#pragma mark -------- 获取组管理员数据
-(void)guestManagementArray
{
    [self clearAllArray];
    [self initGuestData];
    [self initCommunitysData];
    [managementArray addObject:firstSectionArray];
    [managementArray addObject:thirdSectionArray];
}

#pragma mark --------- 加载成员数据
-(void)initStaffData
{
    ManagementModel * staffModel = [[ManagementModel alloc]init];
    staffModel.imageNameString = @"Staff";
    staffModel.titleNameString = NSLocalizedString(@"staff", @"成员");
    [firstSectionArray addObject:staffModel];
}

#pragma mark --------- 加载客户数据
-(void)initGuestData
{
    ManagementModel * guestModel = [[ManagementModel alloc]init];
    guestModel.imageNameString = @"Client";
    guestModel.titleNameString = NSLocalizedString(@"guest", @"客户");
    [firstSectionArray addObject:guestModel];
}

#pragma mark ----------- 加载物业管理数据
-(void)initCommuntiyManageData
{
    ManagementModel * communityManageModel = [[ManagementModel alloc]init];
    communityManageModel.imageNameString = @"community";
    communityManageModel.titleNameString = NSLocalizedString(@"communityManage", @"物业管理");
    [secondeSectionArray addObject:communityManageModel];
}

#pragma mark ----------- 加载多物业数据
-(void)initCommunitysData
{
    ManagementModel * communtiysModel = [[ManagementModel alloc]init];
    communtiysModel.imageNameString = @"Communitys";
    communtiysModel.titleNameString = NSLocalizedString(@"moreCommuntiy", @"多个物业");
    [thirdSectionArray addObject:communtiysModel];
}


#pragma mark -----------清除所有数据
-(void)clearAllArray
{
    [managementArray removeAllObjects];
    [firstSectionArray removeAllObjects];
    [secondeSectionArray removeAllObjects];
    [thirdSectionArray removeAllObjects];
}

@end
